#include<bits/stdc++.h>
#define MAXN 100100
using namespace std;
bool col[MAXN];
int a[MAXN];
int n;
int maxn=-1;
void dfs(int dep){
    if(dep==n+1){
        int r=0,b=0;
        int ans=0;
        for(int i=1;i<=n;i++){
            if(!col[i]){
                if(a[i]==a[r])ans+=a[i];
                r=i;
            }
            else{
                if(a[i]==a[b])ans+=a[i];
                b=i;
            }
        }
        maxn=max(maxn,ans);
        return;
    }
    dfs(dep+1);
    col[dep]=1;
    dfs(dep+1);
    col[dep]=0;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        dfs(1);
        cout<<maxn<<endl;
        maxn=-1;
    }
    return 0;
}